﻿/*
 * Copyright © 2011 Tristan Reeves, treeves@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using Sprinkles.Tests.TestClasses;

namespace Sprinkles.Tests.DeploymentHosts
{
    public class DummyHost : DeploymentHost
    {
        private string Qualify(string name)
        {
            return "DummyHost." + name;
        }

        public class X
        {
            public TestClass4 Default { get; set; } 
        }

        protected override void RegisterDeployments()
        {
            Register<TestClass4>().Done();
            Register<TestClass4>(Qualify("me4")).Done();
            var me4 = Register<TestClass4>().Name(Qualify("me4")).Done();

            SetDefaultMapping<TestClass4>(me4.GetName);
            SetAlias("the_default_me4", me4.GetName);
            SetAlias("using_global_default", Qualify("using_global_default"));
            Register<X>(Qualify("using_global_default"))
                .Property(x => x.Default).SetAuto()
                .Done();

            Register<TestClass5>().Name(Qualify("me5"))
                .LazyInit(false)
                .Done();

            Register<TestClass1>().Name(Qualify("singleton")).Singleton(true).Done();
            Register<TestClass1>().Name(Qualify("non-singleton")).Singleton(false).Done();

            var c_original = Register<ConstructorTest1>()
                .Name(Qualify("constructor1.obj"))
                .CreatedBy.Constructor((int x) => new ConstructorTest1(x))
                    .SetLiteral(5)
                .Done();

            var c1 = Register<ConstructorTest1>()
                .IsDefaultFor<ConstructorTest1>()
                .Name(Qualify("constructor1.obj"))
                .CreatedBy.Constructor((int x) => new ConstructorTest1(x))
                    .SetLiteral(505)
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify("constructor1.exp"))
                .CreatedBy.Constructor((int x) => new ConstructorTest1(x))
                    .SetExpression("77+33")
                .Done();

            Register<ConstructorTest1>()
                .Name(Qualify("constructor1.ph"))
                .CreatedBy.Constructor((int x) => new ConstructorTest1(x))
                    .SetPlaceholder("${x}").
                Done();

            Register<ConstructorTest2>()
                .Name(Qualify("constructor2.ref"))
                .CreatedBy.Constructor((ConstructorTest1 x) => new ConstructorTest2(x))
                    .SetReference(Qualify("constructor1.obj")).
                Done();

            Register<ConstructorTest2>()
                .Name(Qualify("constructor2.updatableref"))
                .CreatedBy.Constructor((ConstructorTest1 x) => new ConstructorTest2(x))
                    .SetReference(c1)
                .Done();

            Register<ConstructorTest2>()
                .Name(Qualify("constructor2.auto"))
                .CreatedBy.Constructor((ConstructorTest1 x) => new ConstructorTest2(x))
                    .SetAuto()
                .Done();
        }

        protected override bool Include { get { return ALLOW; } }
        public static bool ALLOW = true;
    }
}
